package bg.tu.varna.pms.model.communication;

import java.io.Serializable;
import java.util.Calendar;
import java.util.UUID;

import bg.tu.varna.pms.model.Contact;

public final class SearchMessage {
	public final static class Request implements Serializable {
		private static final long serialVersionUID = 1709492310429406234L;
		private String mUsername;
		private String mNickname;
		private String mName, mSurname, mFamily;
		private Calendar mDateOfBirth;

		public Request(String username, String nickname, String name,
				String surname, String family, Calendar dateOfBirth) {
			mUsername = username;
			mNickname = nickname;
			mName = name;
			mSurname = surname;
			mFamily = family;
			mDateOfBirth = dateOfBirth;
		}

		public String getUsername() {
			return mUsername;
		}

		public String getNickname() {
			return mNickname;
		}

		public String getName() {
			return mName;
		}

		public String getSurname() {
			return mSurname;
		}

		public String getFamily() {
			return mFamily;
		}

		public Calendar getDateOfBirth() {
			return mDateOfBirth;
		}

		public Request setUsername(String username) {
			mUsername = username;
			return this;
		}

		public Request setNickname(String nickname) {
			mNickname = nickname;
			return this;
		}

		public Request setName(String name) {
			mName = name;
			return this;
		}

		public Request setSurname(String surname) {
			mSurname = surname;
			return this;
		}

		public Request setFamily(String family) {
			mFamily = family;
			return this;
		}

		public Request setDateOfBirth(Calendar dateOfBirth) {
			mDateOfBirth = dateOfBirth;
			return this;
		}
	}

	public final static class PageRequest implements Serializable {
		private static final long serialVersionUID = -3299431088943777674L;
		private UUID mSearchID;
		private int mPage;

		public PageRequest(UUID searchID, int page) {
			setSearchID(searchID);
			setPage(page);
		}

		public UUID getSearchID() {
			return mSearchID;
		}

		public void setSearchID(UUID searchID) {
			mSearchID = searchID;
		}

		public int getPage() {
			return mPage;
		}

		public void setPage(int page) {
			mPage = page;
		}
	}

	public final static class Response implements Serializable {
		private static final long serialVersionUID = 253005124889569014L;
		private final UUID mSearchID;
		private final int mResults;
		private final int mPage;
		private final int mPages;
		private final Contact[] mContacts;

		public static final int mResultsPerPage = 20;

		public Response(UUID searchID, int results, int page,
				Contact... contacts) {
			mSearchID = searchID;
			mResults = results;
			mPage = page;
			mPages = (int) Math.floor((double) results
					/ (double) mResultsPerPage);
			mContacts = contacts;
		}

		public Response(int results, Contact... contacts) {
			this(UUID.randomUUID(), results, 0, contacts);
		}

		public UUID getSearchID() {
			return mSearchID;
		}

		public int getResults() {
			return mResults;
		}

		public int getPage() {
			return mPage;
		}

		public int getPages() {
			return mPages;
		}

		public Contact[] getContacts() {
			return mContacts;
		}
	}
}
